package com.lean.android.ad.workflow

import android.app.Activity
import com.lean.android.ad.core.PrivacyDialogBlockChain
import com.lean.android.ad.core.VipDialogBlockChain
import com.lean.android.ad.repository.localcache.AdLocalCache

object WorkFlows {

    @JvmStatic
    fun startMainFlow(activity: Activity, callback: MainFlowCallback) {
        val nodes = buildList {
            add(InterstitialNode(activity))
            val vipShowed = AdLocalCache.vipDialogShowed
            if (!vipShowed) {
                add(VipDialogNode(activity, callback))
                add(InterstitialNode(activity))
            }

            if (!AdLocalCache.isPrivacyAgree) {
                add(PrivacyDialogNode(activity, callback))
                if (vipShowed) {//展示隐私弹窗时，若没有权益弹窗，则加入插屏
                    add(InterstitialNode(activity))
                }
            }
        }

        SequenceWorkFlow(nodes, onComplete = {
            callback.onFlowComplete()
        }).start()

    }

    interface MainFlowCallback {

        fun showPrivacyDialog(chain: PrivacyDialogBlockChain)

        fun showVipDialog(chain: VipDialogBlockChain)

        fun onFlowComplete() {}

    }

}